j= input ()
 
if len(str(j)) != 4:
    print(0)
else:
    qr = False
    for length in range(4, 0, -1):
        if qr:
            break
        for i in range(4 - length + 1):
            vvv = int(str(j)[i:i+length])
            if vvv < 2:
                continue
            for j in range(2, int(vvv**0.5) + 1):
                if vvv % j == 0:
                    break
            else:
                print(vvv)
                qr = True
                break
    if not qr:
        print(0)
